package com.chuang.bootplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chuang.bootplus.base.utils.ApiResponse;
import com.chuang.bootplus.base.utils.BeanUtil;
import com.chuang.bootplus.entity.Tips;
import com.chuang.bootplus.mapper.TipsMapper;
import com.chuang.bootplus.po.TipsInfoPO;
import com.chuang.bootplus.service.TipsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chuang.bootplus.vo.TipsInfoVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-08-17
 */
@Service
public class TipsServiceImpl extends ServiceImpl<TipsMapper, Tips> implements TipsService {

    @Override
    public ApiResponse<TipsInfoVO> info(TipsInfoPO po) {
        List<Tips> tipsList = list(new LambdaQueryWrapper<Tips>().eq(Tips::getType, po.getType()));
        Tips tip = tipsList.get((int) (Math.random() * tipsList.size()));
        return new ApiResponse<>(BeanUtil.beanA2beanB(tip,TipsInfoVO.class));
    }
}
